package com.basic.interupte;


public class CancelTaskTest {

	public static void main(String[] args) {
		
		final Thread t = new Thread(new Runnable() {
			public void run() {
				while (!Thread.interrupted()) {
					System.out.println("任务正在执行......");
				}
				System.out.println("任务被取消执行！");
			}
		});
		t.start();
		
		Thread cancelTaskThread = new Thread(new Runnable() {
			public void run() {
				try {
					Thread.sleep(1000);
					t.interrupt();
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
		});
		
		cancelTaskThread.start();
	}
}
